package org.baojie.raft.node;

import sun.plugin.navig.motif.OJIPlugin;

import java.io.Serializable;

// 节点在群组中的位置定位
public class NodeAddress implements Serializable {
    private static final long serialVersionUID = -301740151714218932L;
    // ip 或 域名
    private final String host;
    // 端口
    private final int port;

    public NodeAddress(String host, int port) {
        this.host = host;
        this.port = port;
    }

    public String getHost() {
        return host;
    }

    public int getPort() {
        return port;
    }

    @Override
    public boolean equals(Object obj) {
        if (null == obj) {
            return false;
        }
        if (this == obj) {
            return true;
        }
        if (obj instanceof NodeAddress) {
            NodeAddress tmp = (NodeAddress) obj;
            if (!this.host.equals(tmp.host)) {
                return false;
            }
            if (this.port != tmp.port) {
                return false;
            }
            return true;
        } else {
            return false;
        }
    }

    @Override
    public int hashCode() {
        int result = 17;
        result = 31 * result + host.hashCode();
        result = 31 * result + port;
        return result;
    }

    @Override
    public String toString() {
        return "Address{" +
                "host='" + host + '\'' +
                ", port=" + port +
                '}';
    }

}
